/**
 * 
 */
package com.gragra.util.tests;
import static org.junit.Assert.*;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import org.junit.Before;
import org.junit.Test;
import com.gragra.util.DeepIntNumberer;
/**
 * @author Christoph Teichmann
 * created Mar 28, 2013 7:32:12 PM
 * @version 0.1
 */
public class TestDeepIntNumberer
{
	/**
	 * 
	 */
	private DeepIntNumberer din;
	/**
	 *
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception
	{din = new DeepIntNumberer();}
	/**
	 * Test method for {@link com.gragra.util.DeepIntNumberer#lookUp(int[])}.
	 */
	@Test
	public final void testLookUp()
	{
		int[] arr1 = new int[] {};
		int[] arr3 = new int[] {1,2,4};
		int[] arr4 = new int[] {2,2};
		int[] arr5 = new int[] {1,3,5};
		assertEquals(din.lookUp(arr5),-1);
		assertEquals(din.assignNew(arr5),0);
		assertEquals(din.lookUp(arr5),0);
		assertEquals(din.ensure(arr5),0);
		assertEquals(din.lookUp(arr4),-1);
		assertEquals(din.assignNew(arr4),1);
		assertEquals(din.lookUp(arr4),1);
		assertEquals(din.ensure(arr4),1);
		assertEquals(din.lookUp(arr5),0);
		assertEquals(din.ensure(arr5),0);
		assertEquals(din.lookUp(arr3),-1);
		assertEquals(din.ensure(arr3),2);
		assertEquals(din.lookUp(arr3),2);
		assertEquals(din.ensure(arr3),2);
		assertEquals(din.lookUp(arr4),1);
		assertEquals(din.ensure(arr4),1);
		assertEquals(din.lookUp(arr5),0);
		assertEquals(din.lookUp(arr1),-1);
		assertEquals(din.ensure(arr1),3);
		assertEquals(din.lookUp(arr1),3);
		assertEquals(din.ensure(arr1),3);
		assertEquals(din.ensure(arr3),2);
		assertEquals(din.lookUp(arr3),2);
		assertEquals(din.ensure(arr3),2);
		assertEquals(din.lookUp(arr4),1);
		assertEquals(din.ensure(arr4),1);
		assertEquals(din.lookUp(arr5),0);
		assertEquals(din.ensure(arr5),0);
	}
	/**
	 * Test method for {@link com.gragra.util.DeepIntNumberer#ensure(it.unimi.dsi.fastutil.ints.IntList)}.
	 */
	@Test
	public final void testEnsureIntList()
	{
		IntArrayList arr5 = new IntArrayList();
		arr5.add(1);
		arr5.add(3);
		arr5.add(5);
		IntArrayList arr4 = new IntArrayList();
		arr4.add(2);
		arr4.add(2);
		IntArrayList arr3 = new IntArrayList();
		arr3.add(2);
		arr3.add(3);
		arr3.add(2);
		arr3.add(3);
		arr3.add(2);
		arr3.add(3);
		arr3.add(4);
		IntArrayList arr1 = new IntArrayList();
		arr5.add(2);
		arr5.add(3);
		arr5.add(2);
		arr5.add(3);
		assertEquals(din.getNumberIfExisting(arr5),-1);
		assertEquals(din.ensure(arr5),0);
		assertEquals(din.getNumberIfExisting(arr5),0);
		assertEquals(din.ensure(arr5),0);
		assertEquals(din.getNumberIfExisting(arr4),-1);
		assertEquals(din.ensure(arr4),1);
		assertEquals(din.getNumberIfExisting(arr4),1);
		assertEquals(din.ensure(arr4),1);
		assertEquals(din.getNumberIfExisting(arr5),0);
		assertEquals(din.ensure(arr5),0);
		assertEquals(din.getNumberIfExisting(arr3),-1);
		assertEquals(din.ensure(arr3),2);
		assertEquals(din.getNumberIfExisting(arr3),2);
		assertEquals(din.ensure(arr3),2);
		assertEquals(din.getNumberIfExisting(arr4),1);
		assertEquals(din.ensure(arr4),1);
		assertEquals(din.getNumberIfExisting(arr5),0);
		assertEquals(din.getNumberIfExisting(arr1),-1);
		assertEquals(din.ensure(arr1),3);
		assertEquals(din.getNumberIfExisting(arr1),3);
		assertEquals(din.ensure(arr1),3);
		assertEquals(din.ensure(arr3),2);
		assertEquals(din.getNumberIfExisting(arr3),2);
		assertEquals(din.ensure(arr3),2);
		assertEquals(din.getNumberIfExisting(arr4),1);
		assertEquals(din.ensure(arr4),1);
		assertEquals(din.getNumberIfExisting(arr5),0);
		assertEquals(din.ensure(arr5),0);
	}
}